$('#nbxsd_tabs').tabs({
    border: false,
    onSelect: function (title) {
        if (title == "销售单打印") {
            $.ajax({
                type: "POST",
                url: $.webPath() + '/xsgl/nbxsd/xsdDetail?xsdId=' + $("#nbxsd_id").val(),
                dataType: "html",
                beforeSend: function () {
                    $.messager.progress();
                },
                success: function (data) {
                    $.messager.progress("close");
                    $('#nbxsdy_xsd_id').html(data);
                    if (data.statusCode == 300) {
                    }
                    if (data.statusCode == 200) {
                    }
                }
            });
        }
    }
});


$(function () {
    $("span.ljtip").ljDetail($("#xsd_detail_ljtip").val(), {
        position: 'top'
    });

    $("#nbxsd_xsdmx_table").datagrid({
        url: $.webPath() + '/xsgl/nbxsd/nbxsd_xsmx?xsdId=' + $("#nbxsd_id").val(),
        fitColumns: true,
        singleSelect: true,
        fit: true,
        showFooter: true,
        rownumbers: true,
        columns: [
            [
                {field: 'wzgg.code', title: '物资编码', width: 40},
                {field: 'wzgg.name', title: '物资名称', width: 20},
                {field: 'wzgg.ggxh', title: '规格型号', width: 20},
                {field: 'wzgg.dw', title: '单位', width: 15},
                //{field: 'cd.z', title: '产地', width: 50},
                {field: 'jzfs.z', title: '记重方式', width: 30},
                {field: 'kh.khbm', title: '卡号', width: 50},
                {field: 'xscb', title: '销售成本(元)', width: 40},
                {field: 'js', title: '件数', width: 25},
                {field: 'sbsl', title: '数量', width: 40,
                    formatter: function (value) {
                        var sl = formatSlForHtml(value, ",");
                        return sl;
                    }},
                {field: 'hsj', title: '含税价(元)', width: 30,
                    formatter: function (value) {
                        var sl = formatJeForHtml(value, ",");
                        return sl;
                    } },
                {field: 'hse', title: '含税额(元)', width: 50,
                    formatter: function (value) {
                        var sl = formatJeForHtml2(value, ",");
                        return sl;
                    } },
                {field: 'bhsj', title: '不含税价(元)', width: 30,
                    formatter: function (value) {
                        var sl = formatJeForHtml(value, ",");
                        return sl;
                    } },
                {field: 'bhse', title: '不含税额(元)', width: 50,
                    formatter: function (value) {
                        var sl = formatJeForHtml2(value, ",");
                        return sl;
                    } }

            ]
        ],
        loadFilter: function (data) {
            $.each(data.rows, function () {
                var bhsj = Math.round(this.bhsj * 10000) / 10000;
                var hsj = Math.round(this.hsj * 10000) / 10000;
                var sl = Math.round(this.sbsl * 10000) / 10000;

                if (this.bhsj) {
                    this.bhse = Math.round(multiply(sl, bhsj) * 100) / 100;
                }
                if (this.hsj) {
                    this.hse = Math.round(multiply(sl, hsj) * 100) / 100;
                }
            })
            return data;
        }
    })
})

function viewNbxsdXshtDetail(id) {
    $.window({
        iconCls: 'icon-tip',
        title: "详细信息",
        url: $.webPath() + "/htgl/xshtgl/xshtgl_detail?xshtId=" + id,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}

//=============按钮事件=============================
//  点击出售联，隐藏出库数量
function nbcslClick1(tdName) {
    $("[name='" + tdName + "']").hide();
    $("#xsdy_ck").hide();
    // $("#xsdy_tdrq").hide();

    $("#xsddy_csl").show();
    $("#xsddy_thd").hide();
    $("#xsddy_shd").hide();
}
/*//点击 记账联，显示出库数量
 function jzlClick(tdName) {
 //alert(tdName);
 $("[name='" + tdName + "']").show();
 }*/
//点击 提货单，显示出库数量
function nbthdClick1(tdName) {
    $("[name='" + tdName + "']").show();
    $("#xsdy_ck").hide();
    // $("#xsdy_tdrq").hide();

    $("#xsddy_csl").hide();
    $("#xsddy_thd").show();
    $("#xsddy_shd").hide();
}
//点击   送货单，显示出库数量
function nbshdClick1(tdName) {
    $("[name='" + tdName + "']").show();
    $("#xsdy_ck").show();
    //  $("#xsdy_tdrq").show();

    $("#xsddy_csl").hide();
    $("#xsddy_thd").hide();
    $("#xsddy_shd").show();
}

// 销售配送单打印预览
function xsdyPrintPreview() {
    var LODOP = getLodop(document.getElementById('NBXSD_LODOP_OB'), document.getElementById('NBXSD_LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("预览销售单");

    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbxsdy_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbxsdy_xsd_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbxsdy_detail_id").innerHTML + "</div>";
//    var xsd_xsdh = $("#xsd_xsdh").val();
//    var xsd_ewmtime = $("#xsd_ewmtime").val();

//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
//    LODOP.ADD_PRINT_BARCODE(50, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);

    LODOP.PREVIEW();
}

//销售单打印
function xsdyPrint() {
    var LODOP = getLodop(document.getElementById('NBXSD_LODOP_OB'), document.getElementById('NBXSD_LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("预览销售单");

    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbxsdy_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbxsdy_xsd_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbxsdy_detail_id").innerHTML + "</div>";
//    var xsd_xsdh = $("#xsd_xsdh").val();
//    var xsd_ewmtime = $("#xsd_ewmtime").val();

//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
//    LODOP.ADD_PRINT_BARCODE(50, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);

    LODOP.PREVIEW();
}
